package ext.tianma.bom.service.AllViewBomDisplay;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import ext.com.core.CoreUtil;
import ext.com.iba.IBAUtil;
import ext.drawing.BorrowWorkflowUtil;
import ext.tianma.number.util.PartUtil;
import ext.tianma.part.MyPartUtil;
import ext.tianma.part.PartWorkflowUtil;
import ext.tianma.upload.MyUtil;
import ext.tianma.util.ExportExcelUtil;
import ext.tianma.util.FileDownloadUtil;
import ext.tianma.util.PropertiesUtil;
import wt.access.AccessControlHelper;
import wt.access.AccessPermission;
import wt.content.ApplicationData;
import wt.content.ContentHelper;
import wt.content.FormatContentHolder;
import wt.doc.WTDocument;
import wt.doc.WTDocumentMaster;
import wt.enterprise.Master;
import wt.enterprise.RevisionControlled;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.collections.WTArrayList;
import wt.fc.collections.WTCollection;
import wt.httpgw.URLFactory;
import wt.inf.container.WTContainer;
import wt.method.RemoteMethodServer;
import wt.org.WTPrincipal;
import wt.part.WTPart;
import wt.part.WTPartDescribeLink;
import wt.part.WTPartHelper;
import wt.part.WTPartMaster;
import wt.part.WTPartReferenceLink;
import wt.part.WTPartSubstituteLink;
import wt.part.WTPartUsageLink;
import wt.pom.PersistenceException;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import wt.vc.Iterated;
import wt.vc.VersionControlHelper;
import wt.vc.VersionReference;

/**
 * 根据物料编号获取图文档service
 * 
 * @author lilin
 * @date 2018-11-21 00:37:22
 * 
 */
public class AllViewBomDisplayService {
	private static final String PART_DESCRIPTION = "partDescription";// 物料描述
	private static String configFilePath = "codebase" + File.separator + "ext" + File.separator + "tianma"
			+ File.separator + "cfg" + File.separator + "TianmaPro.properties";// 配置文件路径
	private static PropertiesUtil ut = new PropertiesUtil(configFilePath);// 配置文件util
	private static String domain = ut.getValueByKey("system.domain");// 获取域名

	/**
	 * 全bom展示
	 * 
	 * @param number
	 * @param view
	 * @return
	 * @throws JSONException
	 * @throws RemoteException
	 * @throws IOException
	 */
	public static String getAllViewBom(String number, String view) throws JSONException, RemoteException {
		JSONObject jsonAllObject = new JSONObject();
		String isNotSucess = "true";
		String tip = "查询成功！";
		try {
			WTPart wtpart = PartUtil.getWTPartByNumber(number);// 获取最新版本的部件
			if (wtpart == null) {
				isNotSucess = "false";
				tip = "物料不存在！";
			} else {
				JSONArray viewArray = new JSONArray();// 所有视图的array
				boolean isExitChild = false;// 是否存在bom
				//子物料全BOM查看
				if (!"".equals(view)) {
					JSONObject viewObject = new JSONObject();// 所有视图的Object
					wtpart = CoreUtil.getWTPartByNumberAndView(wtpart.getNumber(), view);
					List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(wtpart);
					if (allUsageLinkList.size() > 0) {
						isExitChild = true;
						viewObject.put("view", wtpart.getViewName());
						viewObject.put("number", wtpart.getNumber());
						viewArray.put(viewObject);
					}
				} 
				//查询输入部件编号的全视图结构
				else {
					WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(wtpart);// 获取所有视图
					WTArrayList viewList = new WTArrayList();
					for (int j = 0; j < viewPartList.size(); j++) {// 循环查找所有视图的子件判断
						JSONObject viewObject = new JSONObject();// 所有视图的Object
						WTPart part = (WTPart) viewPartList.getPersistable(j);
						List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(part);
						if (allUsageLinkList.size() > 0) {
							isExitChild = true;
							viewList.add(part);
							wtpart = part;//用于展示初始化BOM结构数据所用
							viewObject.put("view", part.getViewName());
							viewObject.put("number", part.getNumber());
							viewArray.put(viewObject);
						}else {//为了前端区分是否有BOM结构展示所用
							viewList.add(part);
							viewObject.put("view", part.getViewName());
							viewObject.put("number", "");
							viewArray.put(viewObject);
						}
					}
				}

				if (!isExitChild) {
					isNotSucess = "false";
					tip = "物料不存在BOM结构！";
				} else {
					JSONArray jsonArray = new JSONArray();
					int level = 0;
					JSONObject jsonObject = new JSONObject();// 存放部件对象的Object
					Object partDescriptionObject = IBAUtil.getIBAValue(wtpart, PART_DESCRIPTION);
					String partState = wtpart.getState().getState().getDisplay(Locale.CHINA);//
					jsonObject.put("level", level);// 层级
					jsonObject.put("partNumber", wtpart.getNumber());// 物料编号
					jsonObject.put("partNumberURL", partGenerateInfoPageURL(wtpart));// 物料编号URL
					jsonObject.put("partDescription",
							partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
					jsonObject.put("partVersion", getVersion(wtpart));// 最新版本
					jsonObject.put("viewStr", viewArray);// 所有父件视图对象
					jsonObject.put("subPart", "");
					jsonObject.put("partState", partState);// 状态
					jsonArray.put(jsonObject);// 父件
					jsonArray = getAllUsageLinkByParentPart(wtpart, level, jsonArray);// 递归查询所有子件，子件信息集合
					jsonAllObject.put("partDate", jsonArray);// 物料数据字符串
				}
			}
		} catch (WTException e) {
			isNotSucess = "false";
			tip = "物料查询BOM异常！";
			e.printStackTrace();
		} finally {
			jsonAllObject.put("sucess", isNotSucess);
			jsonAllObject.put("tip", tip);
		}

		return jsonAllObject.toString();
	}

	/**
	 * 全bom展示，文档展示
	 * 
	 * @param number
	 * @param view
	 * @return
	 * @throws JSONException
	 * @throws RemoteException
	 * @throws IOException
	 */
	public static String getAllDoc(String number) throws JSONException, RemoteException {
		JSONObject jsonAllObject = new JSONObject();
		String isNotSucess = "true";
		String tip = "查询成功！";
		ReferenceFactory rf = new ReferenceFactory();
		
		try {
			WTPart wtpart = PartUtil.getWTPartByNumber(number);// 获取最新版本的部件
			String baseHref = new wt.httpgw.URLFactory().getBaseHREF();
			if (wtpart == null) {
				isNotSucess = "false";
				tip = "物料不存在！";
			} else {
				JSONArray jsonArray = new JSONArray();
				WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(wtpart);// 获取所有视图
				List<String> list = new ArrayList<String>();
				for (int j = 0; j < viewPartList.size(); j++) {// 循环查找所有视图的子件判断
					WTPart part = (WTPart) viewPartList.getPersistable(j);
					String level = "1";
					JSONObject jsonObject = new JSONObject();// 存放部件对象的Object
					Object partDescriptionObject = IBAUtil.getIBAValue(part, PART_DESCRIPTION);
					String partState = part.getState().getState().getDisplay(Locale.CHINA);//
					jsonObject.put("level", level);// 层级
					jsonObject.put("partNumber", part.getNumber());// 物料编号
					jsonObject.put("partNumberURL", partGenerateInfoPageURL(part));// 物料编号URL
					jsonObject.put("partDescription",
							partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
					jsonObject.put("partVersion", getVersion(part));// 最新版本
					jsonObject.put("viewStr", part.getViewName());// 所有父件视图对象
					jsonObject.put("subPart", "");
					jsonObject.put("partState", partState);// 状态
					jsonArray.put(jsonObject);// 父件
					jsonArray = getAllUsageLinkByParentPartForDoc(part, level, jsonArray);// 递归查询所有子件，子件信息集合
				}
				// jsonAllObject.put("partDate", jsonArray);// 物料数据字符串
				JSONArray jsonDocArray = new JSONArray();// 获取所有文档对象
				if (jsonArray.length() > 0) {
					boolean flag = true;
					for (int i = 0; i < jsonArray.length(); i++) {
						JSONObject jsonObjectTemp = jsonArray.getJSONObject(i);
						String numberTemp = (String) jsonObjectTemp.get("partNumber");
						String viewTemp = (String) jsonObjectTemp.get("viewStr");
						WTPart tempPart = CoreUtil.getWTPartByNumberAndView(numberTemp, viewTemp);// 查询对应视图的物料
						// WTArrayList tempViewPartList = PartWorkflowUtil.getAllViewParts(tempPart);//
						// 获取所有视图
						// for (int j = 0; j < tempViewPartList.size(); j++) {// 循环查找所有视图的子件判断
						// WTPart tempDocPart = (WTPart) tempViewPartList.getPersistable(j);
						List<WTDocument> allDocList = new ArrayList<WTDocument>();
						List<WTDocument> referenceList = getReferenceDoc(tempPart);// 根据part得到参考关系的文档集合
						List<WTDocument> describeList = getDescribeDoc(tempPart);// 获取描述文档
						allDocList.addAll(referenceList);
						allDocList.addAll(describeList);
						List<WTDocument> newAllDocList = new ArrayList<WTDocument>(new HashSet(allDocList));// 去重

						if (newAllDocList.size() > 0) {
							flag = false;
							for (WTDocument wtDoc : newAllDocList) {
								JSONObject jsonDocObject = new JSONObject();
								String version = VersionControlHelper.getIterationDisplayIdentifier(wtDoc).toString();
								String oid = rf.getReferenceString(wtDoc);
								String cioids = MyUtil.getPrimaryId(wtDoc);
								String docURL = baseHref + "servlet/AttachmentsDownloadDirectionServlet?oid=" +oid+ "&cioids=" +cioids;
								Object tempPartDescriptionObject = IBAUtil.getIBAValue(tempPart, PART_DESCRIPTION);
								jsonDocObject.put("partNumber", tempPart.getNumber());// 物料的详细页面路径
								jsonDocObject.put("partNumberURL", partGenerateInfoPageURL(tempPart));// 物料的详细页面路径
								jsonDocObject.put("partDescription",
										tempPartDescriptionObject == null ? "" : tempPartDescriptionObject.toString());// 物料描述
								jsonDocObject.put("partVersion", getVersion(tempPart));// 最新版本
								//jsonDocObject.put("partView", tempPart.getViewName());// 视图产地
								jsonDocObject.put("docName", wtDoc.getName());// 文档名字
								jsonDocObject.put("docNumber", wtDoc.getNumber());// 文档编号
								jsonDocObject.put("docNumberURL", docGenerateInfoPageURL(wtDoc));// 文档编号
								jsonDocObject.put("docVersion", version);// 文档版本
								jsonDocObject.put("docURL", docURL);// 文档浏览
								String str = tempPart.getNumber()+wtDoc.getNumber();
								if(!list.contains(str)) {//去重复，用文档编号和物料编号来判断list中是否已经存在
									list.add(str);
									jsonDocArray.put(jsonDocObject);//list中不存在就添加
								}
							}
						}
					}
					jsonAllObject.put("docDate", jsonDocArray);// 文档数据字符串
					if (flag) {
						isNotSucess = "false";
						tip = "物料下不存在文档！";
					}
				} else {
					isNotSucess = "false";
					tip = "物料下不存在文档！";
				}

			}
		} catch (WTException e) {
			isNotSucess = "false";
			tip = "物料查询文档异常！";
			e.printStackTrace();
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		} finally {
			jsonAllObject.put("sucess", isNotSucess);
			jsonAllObject.put("tip", tip);
		}
		return jsonAllObject.toString();
	}
	/**
	 * 全bom展示，文档展示，仅查询文档状态为已发布的文档
	 *
	 * @param number
	 * @param view
	 * @return
	 * @throws JSONException
	 * @throws RemoteException
	 * @throws IOException
	 */
	public static String getAllReleasedDoc(String number) throws JSONException, RemoteException {
		System.out.println("开始查询物料对应的文档，仅查询文档状态为已发布的：");
		JSONObject jsonAllObject = new JSONObject();
		String isNotSucess = "true";
		String tip = "查询成功！";
		ReferenceFactory rf = new ReferenceFactory();

		try {
			WTPart wtpart = PartUtil.getWTPartByNumber(number);// 获取最新版本的部件
			String baseHref = new wt.httpgw.URLFactory().getBaseHREF();
			if (wtpart == null) {
				isNotSucess = "false";
				tip = "物料不存在！";
			} else {
				JSONArray jsonArray = new JSONArray();
				WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(wtpart);// 获取所有视图
				List<String> list = new ArrayList<String>();
				for (int j = 0; j < viewPartList.size(); j++) {// 循环查找所有视图的子件判断
					WTPart part = (WTPart) viewPartList.getPersistable(j);
					String level = "1";
					JSONObject jsonObject = new JSONObject();// 存放部件对象的Object
					Object partDescriptionObject = IBAUtil.getIBAValue(part, PART_DESCRIPTION);
					String partState = part.getState().getState().getDisplay(Locale.CHINA);//

					jsonObject.put("level", level);// 层级
					jsonObject.put("partNumber", part.getNumber());// 物料编号
					jsonObject.put("partNumberURL", partGenerateInfoPageURL(part));// 物料编号URL
					jsonObject.put("partDescription",
							partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
					jsonObject.put("partVersion", getVersion(part));// 最新版本
					jsonObject.put("viewStr", part.getViewName());// 所有父件视图对象
					jsonObject.put("subPart", "");
					jsonObject.put("partState", partState);// 状态
					jsonArray.put(jsonObject);// 父件
					jsonArray = getAllUsageLinkByParentPartForDoc(part, level, jsonArray);// 递归查询所有子件，子件信息集合
				}
				// jsonAllObject.put("partDate", jsonArray);// 物料数据字符串
				JSONArray jsonDocArray = new JSONArray();// 获取所有文档对象
				if (jsonArray.length() > 0) {
					boolean flag = true;
					for (int i = 0; i < jsonArray.length(); i++) {
						JSONObject jsonObjectTemp = jsonArray.getJSONObject(i);
						String numberTemp = (String) jsonObjectTemp.get("partNumber");
						String viewTemp = (String) jsonObjectTemp.get("viewStr");
						WTPart tempPart = CoreUtil.getWTPartByNumberAndView(numberTemp, viewTemp);// 查询对应视图的物料
						// WTArrayList tempViewPartList = PartWorkflowUtil.getAllViewParts(tempPart);//
						// 获取所有视图
						// for (int j = 0; j < tempViewPartList.size(); j++) {// 循环查找所有视图的子件判断
						// WTPart tempDocPart = (WTPart) tempViewPartList.getPersistable(j);
						List<WTDocument> allDocList = new ArrayList<WTDocument>();
//						List<WTDocument> referenceList = getReferenceDoc(tempPart);// 根据part得到参考关系的文档集合
						List<WTDocument> referenceList =getReferenceReleasedDoc(tempPart);// 根据part得到参考关系的文档集合
//						List<WTDocument> describeList = getDescribeDoc(tempPart);// 获取描述文档
						List<WTDocument> describeList = getDescribeReleasedDoc(tempPart);// 获取描述文档


						allDocList.addAll(referenceList);
						allDocList.addAll(describeList);
						List<WTDocument> newAllDocList = new ArrayList<WTDocument>(new HashSet(allDocList));// 去重

						if (newAllDocList.size() > 0) {
							flag = false;
							for (WTDocument wtDoc : newAllDocList) {
								JSONObject jsonDocObject = new JSONObject();
								String version = VersionControlHelper.getIterationDisplayIdentifier(wtDoc).toString();
								String oid = rf.getReferenceString(wtDoc);
								String cioids = MyUtil.getPrimaryId(wtDoc);
								String docURL = baseHref + "servlet/AttachmentsDownloadDirectionServlet?oid=" +oid+ "&cioids=" +cioids;
								Object tempPartDescriptionObject = IBAUtil.getIBAValue(tempPart, PART_DESCRIPTION);
								jsonDocObject.put("partNumber", tempPart.getNumber());// 物料的详细页面路径
								jsonDocObject.put("partNumberURL", partGenerateInfoPageURL(tempPart));// 物料的详细页面路径
								jsonDocObject.put("partDescription",
										tempPartDescriptionObject == null ? "" : tempPartDescriptionObject.toString());// 物料描述
								jsonDocObject.put("partVersion", getVersion(tempPart));// 最新版本
								//jsonDocObject.put("partView", tempPart.getViewName());// 视图产地
								jsonDocObject.put("docName", wtDoc.getName());// 文档名字
								jsonDocObject.put("docNumber", wtDoc.getNumber());// 文档编号
								jsonDocObject.put("docNumberURL", docGenerateInfoPageURL(wtDoc));// 文档编号
								jsonDocObject.put("docVersion", version);// 文档版本
								jsonDocObject.put("docURL", docURL);// 文档浏览
								String str = tempPart.getNumber()+wtDoc.getNumber();
								if(!list.contains(str)) {//去重复，用文档编号和物料编号来判断list中是否已经存在
									list.add(str);
									jsonDocArray.put(jsonDocObject);//list中不存在就添加
								}
							}
						}
					}
					jsonAllObject.put("docDate", jsonDocArray);// 文档数据字符串
					if (flag) {
						isNotSucess = "false";
						tip = "物料下不存在文档！";
					}
				} else {
					isNotSucess = "false";
					tip = "物料下不存在文档！";
				}

			}
		} catch (WTException e) {
			isNotSucess = "false";
			tip = "物料查询文档异常！";
			e.printStackTrace();
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		} finally {
			jsonAllObject.put("sucess", isNotSucess);
			jsonAllObject.put("tip", tip);
		}
		return jsonAllObject.toString();
	}

	/**
	 * 判断物料是否存在
	 * 
	 * @param number
	 * @param view
	 * @return
	 * @throws RemoteException
	 * @throws JSONException
	 */
	public static String getChildrenPart(String number, String view) throws RemoteException, JSONException {
		JSONObject jsonAllObject = new JSONObject();
		String isNotSucess = "false";
		String tip = "物料BOM不存在！";
		try {
			WTPart wtpart = PartUtil.getWTPartByNumber(number);// 获取最新版本的部件
			if (!"".equals(view)) {// 存在视图，判断该视图下物料是否存在bom
				wtpart = CoreUtil.getWTPartByNumberAndView(wtpart.getNumber(), view);
				List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(wtpart);
				if (allUsageLinkList.size() > 0) {
					isNotSucess = "true";
					tip = "物料BOM存在！";
				}
			}
		} catch (WTException e) {
			isNotSucess = "false";
			tip = "物料查询BOM异常！";
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			jsonAllObject.put("sucess", isNotSucess);
			jsonAllObject.put("tip", tip);
		}

		return jsonAllObject.toString();
	}

	/**
	 * 导出excel逻辑
	 * 
	 * @param partNumber
	 * @throws WTException
	 * @throws JSONException
	 * @throws IOException
	 */
	public static String excelAllViewBOM(String partNumber) throws JSONException {
		JSONObject ojectExcelURL = new JSONObject();
		String isNotSucess = "true";
		String tip = "导出成功！";
		String fileName = FileDownloadUtil.FolderPath + File.separator + "TempExcel" + File.separator + partNumber
				+ "FullViewBOMShow.xls";
		// 导出数据
		String[] title = { "序号", "层级", "物料编号", "替代料编号", "物料描述", "最新版本号", "产地视图", "状态" };
		//String blank = "";
		HSSFWorkbook wb = new HSSFWorkbook();
		try {
			WTPart wtpart = PartUtil.getWTPartByNumber(partNumber); // 获取最新版本的部件
			if (wtpart != null) {
				WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(wtpart);// 获取所有视图
				if (viewPartList.size() != 0) {
					for (int j = 0; j < viewPartList.size(); j++) {// 循环查找所有视图的子件判断
						JSONArray jsonArray = new JSONArray();
						WTPart part = (WTPart) viewPartList.getPersistable(j);
						if (part != null) {
							List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(part);
							if (allUsageLinkList.size() > 0) {
								int level = 0;
								
								JSONObject jsonObject = new JSONObject();// 存放文档对象的Object
								Object partDescriptionObject = IBAUtil.getIBAValue(part, PART_DESCRIPTION);
								String partState = part.getState().getState().getDisplay(Locale.CHINA);//
								jsonObject.put("level", level);// 层级
								jsonObject.put("partNumber", part.getNumber());// 物料编号
								jsonObject.put("partNumberURL", partGenerateInfoPageURL(part));// 物料编号URL
								jsonObject.put("partDescription",
										partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
								jsonObject.put("partVersion", getVersion(part));// 最新版本
								jsonObject.put("viewStr", part.getViewName());// 所有视图字符串
								jsonObject.put("subPart", "");
								jsonObject.put("partState", partState);// 状态
								jsonArray.put(jsonObject);
								jsonArray = getAllUsageLinkByParentPartForExportExcel(part, level, jsonArray);// 递归查询所有子件，子件信息集合

								// sheet名
								String sheetName = part.getViewName();
								ExportExcelUtil.exportExcel(sheetName, fileName, title, jsonArray, wb);
							}
						}
					}
					FileOutputStream os = new FileOutputStream(fileName);
					wb.write(os);
					os.flush();
					os.close();
				}
				String excelURL = domain + File.separator + "temp" + File.separator + "TempExcel" + File.separator
						+ partNumber + "FullViewBOMShow.xls";
				ojectExcelURL.put("excelURL", excelURL);
			}
		} catch (Exception e) {
			isNotSucess = "false";
			tip = "物料导出异常！";
			e.printStackTrace();
		} finally {
			ojectExcelURL.put("sucess", isNotSucess);
			ojectExcelURL.put("tip", tip);
		}
		return ojectExcelURL.toJSONString();
	}

	/**
	 * 下载主内容
	 * 
	 * @param partNumber
	 * @throws WTException
	 * @throws JSONException
	 * @throws IOException
	 */
	public static String downloadPrimaryFile(String list) throws JSONException {
		String isNotSucess = "true";
		String tip = "下载成功！";
		String lack = "";
		String noDownload ="";
		boolean isExitDoc = false;// 是否存在文档
		JSONObject jsonObjectURL = new JSONObject();
		List<String> listOne = new ArrayList<String>();
		List<String> listTwo = new ArrayList<String>();
		String partNumber ="";
		boolean hasModifiedPrivilege = false;
		try {
			WTPrincipal wtUser = wt.session.SessionHelper.getPrincipal();// 当前登录人
			if (StringUtils.isNotEmpty(list)) {// 返回数据不能为空
				JSONObject obj = new JSONObject(list);
				JSONArray array = new JSONArray(obj.getString("list"));
				if(array.length()>0) {
					for(int i =0; i<array.length(); i++) {
						JSONObject jsonObject = array.getJSONObject(i);
						for(int j =0; j<jsonObject.length(); j++) {
							String docNumber = (String) jsonObject.get("docNumber");
							partNumber = (String) jsonObject.get("partNumber");
							String partNumberShow = (String) jsonObject.get("partNumberShow");
							WTDocument wtDoc = BorrowWorkflowUtil.getDocByNumber(docNumber);
							hasModifiedPrivilege = AccessControlHelper.manager.hasAccess(wtUser, wtDoc, AccessPermission.DOWNLOAD);//当前用户是否有文档的下载权限
							if(hasModifiedPrivilege) {
								boolean flagFile = FileDownloadUtil.downloadPrimaryFile(wtDoc, partNumber,
										partNumberShow + "_"+ wtDoc.getNumber());// 下载主内容到指定文件夹
								if (flagFile) {
									isExitDoc = true;
								}else {
									if(!listTwo.contains("物料"+partNumberShow+"关联的文档"+wtDoc.getNumber()+", "))
										listTwo.add("物料"+partNumberShow+"关联的文档"+wtDoc.getNumber()+", ");
								}
							}else {
								if(!listOne.contains("物料"+partNumberShow+"关联的文档"+wtDoc.getNumber()+", "))
									listOne.add("物料"+partNumberShow+"关联的文档"+wtDoc.getNumber()+", ");
							}
						}
					}
				}
				if(listTwo.size()>0) {
					for(int i =0; i<listTwo.size(); i++) {
						lack = lack + listTwo.get(i);
					}
					lack = lack + "没有主内容！";
				}
				if(listOne.size()>0) {
					for(int i =0; i<listOne.size(); i++) {
						noDownload = noDownload + listOne.get(i);
					}
					noDownload = noDownload + "当前用户没有权限下载！";
				}	
				if (isExitDoc) {
					String path = FileDownloadUtil.FolderPath + File.separator + "PrimaryFileTemp" + File.separator
							+ partNumber;
					if (FileDownloadUtil.fileToZip(path,
							FileDownloadUtil.FolderPath + File.separator + "PrimaryFileTemp", partNumber)) {// 将主内容文件压缩到压缩包
						if (FileDownloadUtil.deleteDir(new File(path))) {// 删除压缩前的文件夹
							String zipURL = domain + File.separator + "temp" + File.separator + "PrimaryFileTemp"
									+ File.separator + partNumber + ".zip";
							jsonObjectURL.put("zipURL", zipURL);
						} else {
							isNotSucess = "false";
							tip = "删除源文件错误！";
						}
					} else {
						isNotSucess = "false";
						tip = "压缩错误！";
					}

				} else {
					isNotSucess = "false";
					tip = "物料不存在主内容或者文档！";
				}
			}
		} catch (Exception e) {
			isNotSucess = "false";
			tip = "物料下载文档异常！";
			e.printStackTrace();
		} finally {
			jsonObjectURL.put("sucess", isNotSucess);
			jsonObjectURL.put("tip", tip);
			jsonObjectURL.put("lack", lack);
			jsonObjectURL.put("noDownload", noDownload);
		}

		return jsonObjectURL.toJSONString();
	}
	

	/**
	 * 根据doc得到文档信息页面url
	 * 
	 * @param part
	 * @return
	 * @throws PersistenceException
	 * @throws WTException
	 */
	public static String docGenerateInfoPageURL(WTDocument doc) throws PersistenceException, WTException {
		String url = "";
		ReferenceFactory referenceFactory = new ReferenceFactory();
		URLFactory urlfactory = new URLFactory();
		String baseHref = urlfactory.getBaseHREF();
		if (doc != null && doc.getNumber() != null) {
			WTContainer container = doc.getContainer();
			String ufid = referenceFactory.getReferenceString(VersionReference.newVersionReference((Iterated) doc));
			String containerOid = "";
			if (container != null) {
				containerOid = referenceFactory.getReferenceString(container);
			}
			if ("".equals(containerOid)) {
				url = baseHref + "app/#ptc1/tcomp/infoPage?oid=" + ufid + "&u8=1";
			} else {
				url = baseHref + "app/#ptc1/tcomp/infoPage?ContainerOid=" + containerOid + "&oid=" + ufid + "&u8=1";
			}
		}
		return url;
	}

	/**
	 * 根据part得到部件信息页面url
	 * 
	 * @param part
	 * @return
	 * @throws PersistenceException
	 * @throws WTException
	 */
	public static String partGenerateInfoPageURL(WTPart part) throws PersistenceException, WTException {
		String url = "";
		ReferenceFactory referenceFactory = new ReferenceFactory();
		URLFactory urlfactory = new URLFactory();
		String baseHref = urlfactory.getBaseHREF();
		if (part != null && part.getNumber() != null) {
			WTContainer container = part.getContainer();
			String ufid = referenceFactory.getReferenceString(VersionReference.newVersionReference((Iterated) part));
			String containerOid = "";
			if (container != null) {
				containerOid = referenceFactory.getReferenceString(container);
			}
			if ("".equals(containerOid)) {
				url = baseHref + "app/#ptc1/tcomp/infoPage?oid=" + ufid + "&u8=1";
			} else {
				url = baseHref + "app/#ptc1/tcomp/infoPage?ContainerOid=" + containerOid + "&oid=" + ufid + "&u8=1";
			}
		}
		return url;
	}

	/**
	 * 根据part得到描述关系的文档集合
	 * 
	 * @param part
	 * @return
	 * @throws WTException
	 */
	public static List<WTDocument> getDescribeDoc(WTPart part) throws WTException {
		List<WTDocument> result = new ArrayList<WTDocument>();
		try {
			if (!RemoteMethodServer.ServerFlag) {
				RemoteMethodServer.getDefault().invoke("getDescribeDoc", AllViewBomDisplayService.class.getName(), null,
						new Class[] { WTPart.class }, new Object[] { part });
			} else {
				boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
				QueryResult qr = PersistenceHelper.manager.navigate(part, WTPartDescribeLink.DESCRIBED_BY_ROLE,
						WTPartDescribeLink.class, false);
				try {
					while (qr.hasMoreElements()) {
						WTPartDescribeLink link = (WTPartDescribeLink) qr.nextElement();
						if (link != null) {
							WTDocument d = link.getDescribedBy();
							d = getLatestDocument((WTDocumentMaster) d.getMaster());
							result.add(d);
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					SessionServerHelper.manager.setAccessEnforced(enforce);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	/**
	 * 根据part得到描述关系的文档集合
	 *
	 * @param part
	 * @return
	 * @throws WTException
	 */
	public static List<WTDocument> getDescribeReleasedDoc(WTPart part) throws WTException {
		List<WTDocument> result = new ArrayList<WTDocument>();
		try {
			if (!RemoteMethodServer.ServerFlag) {
				RemoteMethodServer.getDefault().invoke("getDescribeDoc", AllViewBomDisplayService.class.getName(), null,
						new Class[] { WTPart.class }, new Object[] { part });
			} else {
				boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
				QueryResult qr = PersistenceHelper.manager.navigate(part, WTPartDescribeLink.DESCRIBED_BY_ROLE,
						WTPartDescribeLink.class, false);
				try {
					while (qr.hasMoreElements()) {
						WTPartDescribeLink link = (WTPartDescribeLink) qr.nextElement();
						if (link != null) {
							WTDocument doc = link.getDescribedBy();
							doc = getLatestDocument((WTDocumentMaster) doc.getMaster());
							String docState = doc.getState().getState().getStringValue();
							if ("wt.lifecycle.State.RELEASED".equals(docState)) {// 已发布状态
								result.add(doc);
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					SessionServerHelper.manager.setAccessEnforced(enforce);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 根据part得到参考关系的文档集合
	 * 
	 * @param part
	 * @return
	 * @throws WTException
	 */
	public static List<WTDocument> getReferenceDoc(WTPart part) throws WTException {
		List<WTDocument> result = new ArrayList<WTDocument>();
		try {
			if (!RemoteMethodServer.ServerFlag) {
				RemoteMethodServer.getDefault().invoke("getReferenceDoc", AllViewBomDisplayService.class.getName(),
						null, new Class[] { WTPart.class }, new Object[] { part });
			} else {
				boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
				QueryResult qr = PersistenceHelper.manager.navigate(part, WTPartReferenceLink.REFERENCES_ROLE,
						WTPartReferenceLink.class, false);
				try {
					while (qr.hasMoreElements()) {
						WTPartReferenceLink link = (WTPartReferenceLink) qr.nextElement();
						if (link != null) {
							WTDocumentMaster master = link.getReferences();
							WTDocument d = (WTDocument) getLatestRevision(master);
							result.add(d);
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					SessionServerHelper.manager.setAccessEnforced(enforce);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	/**
	 * 根据part得到参考关系的文档集合,仅获取已发布的文档
	 *
	 * @param part
	 * @return
	 * @throws WTException
	 */
	public static List<WTDocument> getReferenceReleasedDoc(WTPart part) throws WTException {
		List<WTDocument> result = new ArrayList<WTDocument>();
		try {
			if (!RemoteMethodServer.ServerFlag) {
				RemoteMethodServer.getDefault().invoke("getReferenceDoc", AllViewBomDisplayService.class.getName(),
						null, new Class[] { WTPart.class }, new Object[] { part });
			} else {
				boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
				QueryResult qr = PersistenceHelper.manager.navigate(part, WTPartReferenceLink.REFERENCES_ROLE,
						WTPartReferenceLink.class, false);
				try {
					while (qr.hasMoreElements()) {
						WTPartReferenceLink link = (WTPartReferenceLink) qr.nextElement();
						if (link != null) {
							WTDocumentMaster master = link.getReferences();

							//仅获取发布状态的文档
							WTDocument doc = (WTDocument) getLatestRevision(master);
							String docState = doc.getState().getState().getStringValue();
							if ("wt.lifecycle.State.RELEASED".equals(docState)) {// 已发布状态
								result.add(doc);
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					SessionServerHelper.manager.setAccessEnforced(enforce);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 根据master得到 doc
	 * 
	 * @param master
	 * @return
	 */
	public static RevisionControlled getLatestRevision(Master master) {
		RevisionControlled rc = null;
		try {
			if (!RemoteMethodServer.ServerFlag) {
				return (RevisionControlled) RemoteMethodServer.getDefault().invoke("getLatestRevision",
						AllViewBomDisplayService.class.getName(), null, new Class[] { Master.class },
						new Object[] { master });
			} else {
				boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
				if (master != null) {
					try {
						QueryResult qr = VersionControlHelper.service.allVersionsOf(master);
						while (qr.hasMoreElements()) {
							RevisionControlled obj = (RevisionControlled) qr.nextElement();
							if ((rc == null) || (obj.getVersionIdentifier().getSeries()
									.greaterThan(rc.getVersionIdentifier().getSeries()))) {
								rc = obj;
							}
						}
						if (rc != null)
							rc = (RevisionControlled) VersionControlHelper.getLatestIteration(rc, false);
					} catch (WTException e) {

					} finally {
						SessionServerHelper.manager.setAccessEnforced(enforce);
					}
				}
			}
		} catch (Exception e) {
			e.getStackTrace();
		}
		return rc;
	}

	/**
	 * 根据WTDocumentMaster获得最新版WTDocument
	 * 
	 * @param docMaster
	 * @return
	 * @throws WTException
	 * @throws PersistenceException
	 * @throws Exception
	 */
	public static WTDocument getLatestDocument(WTDocumentMaster docMaster) throws PersistenceException, WTException {
		WTDocument document = null;
		if (docMaster != null) {
			QueryResult qr = VersionControlHelper.service.allVersionsOf(docMaster);
			if (qr != null && qr.hasMoreElements()) {
				document = (WTDocument) qr.nextElement();
			}
		}
		return document;
	}

	/**
	 * 获取BOM下所有的子件相关信息（递归查询）适用于物料查询
	 * 
	 * @param parentPart
	 * @return
	 * @throws WTException
	 * @throws JSONException
	 * @throws RemoteException
	 */
	public static JSONArray getAllUsageLinkByParentPart(WTPart parentPart, int level, JSONArray jsonArray)
			throws WTException, JSONException, RemoteException {
		int tempLevel = 0;
		List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(parentPart);
		
		Iterator<WTPartUsageLink> allLinkIterator = allUsageLinkList.iterator();
		while (allLinkIterator.hasNext()) {
			tempLevel = level+1;
			JSONObject jsonObjectTemp = new JSONObject();// 存放文档对象的Object
			WTPartUsageLink partUsageLink = allLinkIterator.next();
			WTPartMaster master = partUsageLink.getUses();
			WTPart usagePart = CoreUtil.getWTPartByMasterAndView(master, parentPart.getViewName());// 根据master和视图获取part
			JSONArray viewArray = new JSONArray();// 所有视图的array
			WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(usagePart);// 获取子件所有视图对象
			for (int j = 0; j < viewPartList.size(); j++) {
				JSONObject viewObject = new JSONObject();// 所有视图的Object
				WTPart wtpart = (WTPart) viewPartList.getPersistable(j);
				List<WTPartUsageLink> childUsageLinkList = MyPartUtil.getFirstLevelUsageLink(wtpart);
				if (childUsageLinkList.size() > 0) {
					viewObject.put("view", wtpart.getViewName());
					viewObject.put("number", wtpart.getNumber());
					viewArray.put(viewObject);
				}else {
					viewObject.put("view", wtpart.getViewName());
					viewObject.put("number", "");
					viewArray.put(viewObject);
				}

			}
			JSONArray subArray = getSubParts(partUsageLink, usagePart);// 获取替代料编号
			String partState = usagePart.getState().getState().getDisplay(Locale.CHINA);
			Object partDescriptionObject = IBAUtil.getIBAValue(usagePart, PART_DESCRIPTION);
			jsonObjectTemp.put("level", tempLevel);// 层级
			jsonObjectTemp.put("partNumber", usagePart.getNumber());// 物料编号
			jsonObjectTemp.put("partNumberURL", partGenerateInfoPageURL(usagePart));// 物料编号URL
			jsonObjectTemp.put("partDescription",
					partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
			jsonObjectTemp.put("partVersion", getVersion(usagePart));// 最新版本
			jsonObjectTemp.put("viewStr", viewArray);
			jsonObjectTemp.put("subPart", subArray);// 替代料信息
			jsonObjectTemp.put("partState", partState);// 状态
			jsonArray.put(jsonObjectTemp);
			getAllUsageLinkByParentPart(usagePart, tempLevel, jsonArray);
		}
		
		return jsonArray;
	}

	/**
	 * 获取BOM下所有的子件相关信息（递归查询）适用于导出excel
	 * 
	 * @param parentPart
	 * @return
	 * @throws WTException
	 * @throws JSONException
	 * @throws RemoteException
	 */
	public static JSONArray getAllUsageLinkByParentPartForExportExcel(WTPart parentPart, int level,
			JSONArray jsonArray) throws WTException, JSONException, RemoteException {
		int tempLevel = 0;
		List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(parentPart);
		Iterator<WTPartUsageLink> allLinkIterator = allUsageLinkList.iterator();
		while (allLinkIterator.hasNext()) {
			tempLevel = level +1;
			String blank = "";
			for(int i=0; i<tempLevel; i++) {
				blank = blank+"   ";
			}
			JSONObject jsonObjectTemp = new JSONObject();// 存放文档对象的Object
			WTPartUsageLink partUsageLink = allLinkIterator.next();
			WTPartMaster master = partUsageLink.getUses();
			WTPart usagePart = CoreUtil.getWTPartByMasterAndView(master, parentPart.getViewName());
			// WTPartToolUtil.getLatestWTPartByMaster(master);// 根据master获取part

			JSONArray subArray = getSubParts(partUsageLink, usagePart);// 获取替代料编号
			String partState = usagePart.getState().getState().getDisplay(Locale.CHINA);
			Object partDescriptionObject = IBAUtil.getIBAValue(usagePart, PART_DESCRIPTION);
			jsonObjectTemp.put("level", tempLevel);// 层级
			jsonObjectTemp.put("partNumber", blank+usagePart.getNumber());// 物料编号
			jsonObjectTemp.put("partNumberURL", partGenerateInfoPageURL(usagePart));// 物料编号URL
			jsonObjectTemp.put("partDescription",
					partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
			jsonObjectTemp.put("partVersion", getVersion(usagePart));// 最新版本
			jsonObjectTemp.put("viewStr", usagePart.getViewName());// 视图
			jsonObjectTemp.put("subPart", subArray);// 替代料信息
			jsonObjectTemp.put("partState", partState);// 状态
			jsonArray.put(jsonObjectTemp);
			getAllUsageLinkByParentPartForExportExcel(usagePart, tempLevel, jsonArray);
		}
		return jsonArray;
	}

	/**
	 * 获取BOM下所有的子件相关信息（递归查询）适用于文档查询
	 * 
	 * @param parentPart
	 * @return
	 * @throws WTException
	 * @throws JSONException
	 * @throws RemoteException
	 */
	public static JSONArray getAllUsageLinkByParentPartForDoc(WTPart parentPart, String level, JSONArray jsonArray)
			throws WTException, JSONException, RemoteException {
		String tempLevel = "";
		int i = 0;
		List<WTPartUsageLink> allUsageLinkList = MyPartUtil.getFirstLevelUsageLink(parentPart);
		Iterator<WTPartUsageLink> allLinkIterator = allUsageLinkList.iterator();
		while (allLinkIterator.hasNext()) {
			i++;
			tempLevel = level + "." + i;
			JSONObject jsonObjectTemp = new JSONObject();// 存放文档对象的Object
			WTPartUsageLink partUsageLink = allLinkIterator.next();
			WTPartMaster master = partUsageLink.getUses();
			WTPart usagePart = CoreUtil.getWTPartByMasterAndView(master, parentPart.getViewName());
			// WTPartToolUtil.getLatestWTPartByMaster(master);// 根据master获取part
			WTArrayList viewPartList = PartWorkflowUtil.getAllViewParts(usagePart);// 获取子件所有视图对象
			for (int j = 0; j < viewPartList.size(); j++) {
				WTPart wtpart = (WTPart) viewPartList.getPersistable(j);
				System.out.println("===view:"+wtpart.getViewName()+"==number:"+wtpart.getNumber());
				JSONArray subArray = getSubParts(partUsageLink, wtpart);// 获取替代料编号
				String partState = wtpart.getState().getState().getDisplay(Locale.CHINA);
				Object partDescriptionObject = IBAUtil.getIBAValue(wtpart, PART_DESCRIPTION);
				jsonObjectTemp.put("level", tempLevel);// 层级
				jsonObjectTemp.put("partNumber", wtpart.getNumber());// 物料编号
				jsonObjectTemp.put("partNumberURL", partGenerateInfoPageURL(wtpart));// 物料编号URL
				jsonObjectTemp.put("partDescription",
						partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
				jsonObjectTemp.put("partVersion", getVersion(wtpart));// 最新版本
				jsonObjectTemp.put("viewStr", wtpart.getViewName());// 视图
				jsonObjectTemp.put("subPart", subArray);// 替代料信息
				jsonObjectTemp.put("partState", partState);// 状态
				jsonArray.put(jsonObjectTemp);
				jsonArray = getAllUsageLinkByParentPartForDoc(wtpart, tempLevel, jsonArray);
			}
		}
		if(allUsageLinkList.size()==0) {
			JSONObject jsonObjectTemp = new JSONObject();// 存放文档对象的Object
			JSONArray subArray = new JSONArray();// 获取替代料编号
			String partState = parentPart.getState().getState().getDisplay(Locale.CHINA);
			Object partDescriptionObject = IBAUtil.getIBAValue(parentPart, PART_DESCRIPTION);
			jsonObjectTemp.put("level", tempLevel);// 层级
			jsonObjectTemp.put("partNumber", parentPart.getNumber());// 物料编号
			jsonObjectTemp.put("partNumberURL", partGenerateInfoPageURL(parentPart));// 物料编号URL
			jsonObjectTemp.put("partDescription",
					partDescriptionObject == null ? "" : partDescriptionObject.toString());// 物料描述
			jsonObjectTemp.put("partVersion", getVersion(parentPart));// 最新版本
			jsonObjectTemp.put("viewStr", parentPart.getViewName());// 视图
			jsonObjectTemp.put("subPart", subArray);// 替代料信息
			jsonObjectTemp.put("partState", partState);// 状态
			jsonArray.put(jsonObjectTemp);
		}
		return jsonArray;
	}

	/**
	 * 获取对象的大小版本组成的版本序列值，形如： A.1
	 * 
	 * @param revisionControlled
	 * @return
	 */
	/**
	 * @param revisionControlled
	 * @return
	 */
	public static String getVersion(RevisionControlled revisionControlled) {

		String version = "";

		if (revisionControlled != null) {
			// 获取大版本
			String majorVersion = revisionControlled.getVersionIdentifier().getValue();

			// 获取小版本
			String minorVersion = revisionControlled.getIterationIdentifier().getValue();

			version = majorVersion + "." + minorVersion;
		}

		return version;
	}

	/**
	 * 获取所有替代件的编号字符串
	 * 
	 * @param usageLink
	 * @param parentPart
	 * @return
	 * @throws JSONException
	 */
	public static JSONArray getSubParts(WTPartUsageLink usageLink, WTPart parentPart) throws JSONException {
		JSONArray subArray = new JSONArray();
		try {
			WTCollection collection = WTPartHelper.service.getSubstituteLinks(usageLink);
			Iterator iterator = collection.persistableIterator();
			while (iterator.hasNext()) {
				JSONObject subObject = new JSONObject();//
				Object tempObject = iterator.next();
				if (tempObject instanceof WTPartSubstituteLink) {
					WTPartSubstituteLink substituteLink = (WTPartSubstituteLink) tempObject;
					WTPartMaster subMaster = substituteLink.getSubstitutes();
					WTPart subPart = CoreUtil.getWTPartByMasterAndView(subMaster, parentPart.getViewName());
					if (subPart != null) {
						// map.put(subPart.getNumber(), partGenerateInfoPageURL(subPart));
						subObject.put("number", subPart.getNumber());
						subObject.put("numberURL", partGenerateInfoPageURL(subPart));
						subArray.put(subObject);
					}
				}
			}
		} catch (WTException e) {
			e.printStackTrace();
		}
		return subArray;
	}

	
	/**
	 * 查看当前用户是否有当前文档的下载权限以及文档是否有主内容
	 * 
	 * @param docNumber
	 * @return
	 * @throws JSONException 
	 */
	public static String queryPermissions(String docNumber) throws JSONException {
		boolean hasModifiedPrivilege = false;
		JSONObject ob = new JSONObject();
		try {
			WTPrincipal wtUser = wt.session.SessionHelper.getPrincipal();// 当前登录人
			//AccessPermission.DOWNLOAD 下载权限
			WTDocument WTDoc = BorrowWorkflowUtil.getDocByNumber(docNumber);//当前文档
			hasModifiedPrivilege = AccessControlHelper.manager.hasAccess(wtUser, WTDoc, AccessPermission.DOWNLOAD);//判断是否有权限下载
			FormatContentHolder aFormatContentHolder = (FormatContentHolder) ContentHelper.service.getContents(WTDoc);
			ApplicationData primary = (ApplicationData) ContentHelper.getPrimary(aFormatContentHolder);//获取文档主内容
			if(primary != null) {
				if(hasModifiedPrivilege) {
					ob.put("status", "success");
					ob.put("message", "yes");
					ob.put("hint", "");
				}else {
					ob.put("status", "success");
					ob.put("message", "no");
					ob.put("hint", "您没有预览此图纸的权限,如需预览请联系管理员!");
				}
			}else {
				ob.put("status", "success");
				ob.put("message", "no");
				ob.put("hint", "此图纸没有主内容!");
			}
		} catch (WTException e) {
			ob.put("status", "error");
			ob.put("message", "接口错误！");
			e.printStackTrace();
		} catch (PropertyVetoException e) {
			ob.put("status", "error");
			ob.put("message", "接口错误！");
			e.printStackTrace();
		}
		return ob.toString();
	}
	
	
	public static void main(String[] args) throws JSONException, RemoteException {

		String number = "GC000001";
		if (!RemoteMethodServer.ServerFlag) {
			System.out.println("Debug   RemoteMethodServer...");
			String method = "getAllViewBom";

			try {
				RemoteMethodServer.getDefault().invoke(method, AllViewBomDisplayService.class.getName(), null,
						new Class[] { String.class }, new Object[] { number });
				System.out.println("Debug  end  RemoteMethodServer...");
			} catch (RemoteException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
		} else {
			// getAllViewBom(number);
		}

	}
	

}
